--- @param extension Package
--- @param HY HY_Utility
--- @param U Utility
return function(extension, HY, U)
    local hy_maeriberii = General:new(extension, "hy_maeriberii", "chi_k", 3, 3, General.Female)
    local pass_membrane = fk.CreateSkill {
        name = "pass_membrane",
    }
    pass_membrane:addEffect("viewas", {
        mute_card = false,
        pattern = ".",
        times = function(self, player)
            return 2 - player:usedSkillTimes(pass_membrane.name, Player.HistoryTurn)
        end,
        expand_pile = function(self, player)
            return player:getTableMark("pass_membrane-turn")
        end,
        card_filter = function(self, player, to_select, selected)
            if #selected == 0 and table.contains(player:getTableMark("pass_membrane-turn"), to_select) then
                local card = Fk:getCardById(to_select)
                if Fk.currentResponsePattern == nil then
                    return player:canUse(card) and not player:prohibitUse(card)
                else
                    return Exppattern:Parse(Fk.currentResponsePattern):match(card)
                end
            end
        end,
        view_as = function(self, player, cards)
            if #cards ~= 1 then return end
            return Fk:getCardById(cards[1])
        end,
        before_use = function(self, player, use)
            use.attachedSkillAndUser = { skillName = pass_membrane.name }
        end,
        enabled_at_play = function(self, player)
            return player:usedSkillTimes(pass_membrane.name, Player.HistoryTurn) < 2 and #player:getViewAsCardNames(pass_membrane.name, Fk:getAllCardNames("btde")) > 0
        end,
        enabled_at_response = function(self, player, response)
            return player:usedSkillTimes(pass_membrane.name, Player.HistoryTurn) < 2 and table.any(player:getTableMark("pass_membrane-turn"), function(id)
                return Fk.currentResponsePattern and Fk.currentResponsePattern:match(Fk:getCardById(id).name)
            end)
        end,
        enabled_at_nullification = function(self, player, data)
            return player:usedSkillTimes(pass_membrane.name, Player.HistoryTurn) < 2 and table.any(player:getTableMark("pass_membrane-turn"), function(id)
                return Fk.currentResponsePattern and Fk.currentResponsePattern:match(Fk:getCardById(id).name)
            end)
        end,
    })
    pass_membrane:addEffect(fk.CardUseFinished, {
        is_delay_effect = true,
        can_trigger = function(self, event, target, player, data)
            return data.from == player and data.attachedSkillAndUser and data.attachedSkillAndUser.skillName == pass_membrane.name and not player.room:getCardOwner(data.card)
        end,
        on_use = function(self, event, target, player, data)
            local room = player.room
            local card = data.card
            room:moveCards({
                ids = { card.id },
                toArea = Card.DrawPile,
                moveReason = fk.ReasonPut,
                skillName = pass_membrane.name,
                proposer = player,
                moveMark = "@@pass_membrane",
                drawPilePosition = -1,
            })
            local event = room.logic:getCurrentEvent():findParent(GameEvent.Turn, true)
            if event then
                event:addExitFunc(function()
                    room:setCardMark(card, "@@pass_membrane", 0)
                    if not room:getCardOwner(card) then
                        room:moveCardTo(card, Card.DiscardPile, nil, fk.ReasonJustMove, pass_membrane.name)
                    end
                end)
            end
        end
    })
    pass_membrane:addEffect(fk.CardRespondFinished, {
        is_delay_effect = true,
        can_trigger = function(self, event, target, player, data)
            return data.from == player and data.attachedSkillAndUser and data.attachedSkillAndUser.skillName == pass_membrane.name and not player.room:getCardOwner(data.card)
        end,
        on_use = function(self, event, target, player, data)
            local room = player.room
            local card = data.card
            room:moveCards({
                ids = { card.id },
                toArea = Card.DrawPile,
                moveReason = fk.ReasonPut,
                skillName = pass_membrane.name,
                proposer = player,
                moveMark = "@@pass_membrane",
                drawPilePosition = -1,
            })
            local event = room.logic:getCurrentEvent():findParent(GameEvent.Turn, true)
            if event then
                event:addExitFunc(function()
                    room:setCardMark(card, "@@pass_membrane", 0)
                    if not room:getCardOwner(card) then
                        room:moveCardTo(card, Card.DiscardPile, nil, fk.ReasonJustMove, pass_membrane.name)
                    end
                end)
            end
        end
    })
    pass_membrane:addEffect(fk.AfterCardsMove, {
        can_refresh = function(self, event, target, player, data)
            for _, move in pairs(data) do
                if move.toArea == Card.DiscardPile then
                    return true
                end
                for _, info in pairs(move.moveInfo) do
                    if info.fromArea == Card.DiscardPile then
                        return true
                    end
                end
            end
        end,
        on_refresh = function(self, event, target, player, data)
            player.room:setPlayerMark(player, "pass_membrane-turn", table.map(HY.GetTurnDiscardPile(player.room), Util.IdMapper))
        end
    })
    local dye_motif = fk.CreateSkill {
        name = "dye_motif",
    }
    dye_motif:addEffect(fk.AfterSkillEffect, {
        can_refresh = function(self, event, target, player, data)
            return player:hasSkill(dye_motif.name) and data.who == player and data.skill.name == pass_membrane.name
        end,
        on_refresh = function(self, event, target, player, data)
            player.room:setPlayerMark(player, "@@dye_motif_record-turn", 1)
        end,
    })
    dye_motif:addEffect(fk.TurnEnd, {
        can_trigger = function(self, event, target, player, data)
            return player:hasSkill(dye_motif.name) and player:getMark("@@dye_motif_record-turn") ~= 0
        end,
        on_cost = Util.TrueFunc,
        on_use = function(self, event, target, player, data)
            local room = player.room
            local cards = room:getNCards(1)
            player:addToPile("$dye_motif", cards, false, dye_motif.name, player)
        end
    })
    dye_motif:addEffect(fk.RoundEnd, {
        can_trigger = function(self, event, target, player, data)
            return player:hasSkill(dye_motif.name) and #player:getPile("$dye_motif") > 0
        end,
        on_cost = Util.TrueFunc,
        on_use = function(self, event, target, player, data)
            local room = player.room
            if #player:getPile("$dye_motif") == 1 then
                room:obtainCard(player, player:getPile("$dye_motif"), false, fk.ReasonPrey, player, dye_motif.name)
            else
                local cards = room:askToCards(player, {
                    min_num = 1,
                    max_num = 1,
                    skill_name = dye_motif.name,
                    expand_pile = "$dye_motif",
                    cancelable = false,
                    pattern = ".|.|.|$dye_motif",
                })
                if type(cards) == "number" then
                    cards = { cards }
                end
                room:obtainCard(player, cards, false, fk.ReasonPrey, player, dye_motif.name)
            end
            if #player:getPile("$dye_motif") >= 8 then
                room:moveCardTo(player:getPile("$dye_motif"), Card.DiscardPile, nil, fk.ReasonPutIntoDiscardPile, dye_motif.name, nil, true, player)
                room:loseHp(player, 2, dye_motif.name)
            end
        end,
    })
    local paradoxes = fk.CreateSkill {
        name = "paradoxes"
    }
    paradoxes:addEffect(fk.TargetConfirmed, {
        can_trigger = function(self, event, target, player, data)
            return player:hasSkill(paradoxes.name) and data.from ~= player and data.to == player and data.card.is_damage_card and player:usedSkillTimes(paradoxes.name) < 1
        end,
        on_cost = Util.TrueFunc,
        on_use = function(self, event, target, player, data)
            local room = player.room
            local cards = room:getNCards(3)
            room:turnOverCardsFromDrawPile(player, cards, paradoxes.name)
            if table.every(cards, function(id1)
                    local others = table.clone(cards)
                    table.removeOne(others, id1)
                    return table.every(others, function(id2)
                        local card1 = Fk:getCardById(id1)
                        local card2 = Fk:getCardById(id2)
                        return card1.trueName ~= card2.trueName and card1.suit ~= card2.suit and card1.number ~= card2.number
                    end)
                end) then
                room:setPlayerMark(player, "@@paradoxes-turn", 1)
            end
            room:cleanProcessingArea(cards)
        end,
    })
    paradoxes:addEffect("prohibit", {
        is_prohibited = function(self, from, to, card)
            if to:hasSkill(paradoxes.name) and to:getMark("@@paradoxes-turn") ~= 0 and from ~= to and card.is_damage_card then
                return true
            end
        end
    })
    extension:loadSkillSkels { pass_membrane, dye_motif, paradoxes }
    hy_maeriberii:addSkills { "pass_membrane", "dye_motif", "paradoxes" }
    Fk:loadTranslationTable {
        ["hy_maeriberii"] = "玛艾露贝莉",
        ["#hy_maeriberii"] = "幻想旅者",
        ["designer:hy_maeriberii"] = "黑曜人形",
        ["illustrator:hy_maeriberii"] = "コロトリシア",
        ["cv:hy_maeriberii"] = "",

        ["pass_membrane"] = "蚀膜",
        [":pass_membrane"] = "每回合限两次，你可以使用或打出本回合进入弃牌堆的牌，以此法使用或打出的牌结算结束后，若此牌不在一名角色的区域内，你将之<a href='temp_operation'>临时</a>置于牌堆底直到本回合结束。",
        ["@@pass_membrane"] = "蚀膜",

        ["dye_motif"] = "融纹",
        [":dye_motif"] = "每回合结束时，若你本回合发动过“蚀膜”，你将牌堆顶的牌扣置于武将牌上。每轮结束时，你获得一张“融纹”牌，然后若剩余牌数不小于八，你将这些牌置入弃牌堆并失去2点体力。",
        ["@@dye_motif_record-turn"] = "蚀膜",
        ["$dye_motif"] = "融纹",
        ["dye_motif_prompt"] = "染纹：你须获得一张“融纹”牌",

        ["paradoxes"] = "异相",
        [":paradoxes"] = "你每回合首次成为其他角色使用的伤害类牌的目标后，亮出牌堆顶三张牌，若牌名、花色、点数均不同，本回合其他角色不能对你使用伤害类牌。",
        ["@@paradoxes-turn"] = "异相",
    }
end
